/*
 * Step.java
 *
 * Created on 18 de julio de 2007, 17:22
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package model;

import org.w3c.dom.Document;

/**
 *
 * @author mariano
 */
public class Step extends xml.Xmlizable{
    private String title;
    private String content;
    
    /** Creates a new instance of Step */
    public Step() {
    }
    
    public Step( String title, String content ) {
        this.title = title;
        this.content = content;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
    
    public xml.Coleccion toXmlColeccion()
    {
        xml.Coleccion col = new xml.Coleccion( "step" );
        col.addNodo( "step-title", this.title );
        col.addNodo( "step-content", this.content );
        
        return col;
    }
    
    public static Step fromXml( String str )
    {
        xml.Item col = xml.Item.fromXml( str );
        return parse( col );
    }
    
    public static Step fromXml( Document doc )
    {
        xml.Item col = xml.Item.fromXml( doc.getFirstChild() );
        return parse( col );
    }
    
    private static Step parse( xml.Item col )
    {
        if( !col.isColeccion() || col.getName() != "step" )
            return null;
        
        xml.Coleccion c = (xml.Coleccion)col;
        
        xml.Nodo title = c.getNodo( 0, "step-title" );
        xml.Nodo content = c.getNodo( 1, "step-content" );
        
        if( title == null )
            return null;
        // permitimos content inexistente
        return new Step( title.getValue(), (title == null)?"":content.getValue() );
    }
    
}
